package com.pansoft.openplanet.adapter;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

import com.pansoft.kline.fragment.BourseFragment;
import com.pansoft.kline.fragment.KLineRiseFallFragment;
import com.pansoft.kline.fragment.KlineOptionalOrMVFragment;
import com.pansoft.kline.model.MarketMenuBean;
import com.pansoft.openplanet.fragment.BtckanDetailFragment;

import java.util.List;

/**
 * Created by cimu on 2018/11/7.
 */

public class BtckanFragmentAdapter extends FragmentStatePagerAdapter {

    private FragmentManager fragmentManager;
    private List<MarketMenuBean.DataBean.CategoryBean.ListBean> coinMenuList;

    public BtckanFragmentAdapter(FragmentManager fm, List<MarketMenuBean.DataBean.CategoryBean.ListBean> coinMenuList) {
        super(fm);
        this.fragmentManager = fm;
        this.coinMenuList = coinMenuList;
    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        MarketMenuBean.DataBean.CategoryBean.ListBean coinMenu = coinMenuList.get(position);
        return coinMenu.getTitle();
    }

    @Override
    public Fragment getItem(int position) {
        MarketMenuBean.DataBean.CategoryBean.ListBean bean = coinMenuList.get(position);
        if (position == 0) {
            //"自选";
            return KlineOptionalOrMVFragment.newInstance(bean);
        } else if (position == 1) {
            //"市值"
            return KlineOptionalOrMVFragment.newInstance(bean);
        } else if (position == 2) {
            // "涨跌幅"
            return KLineRiseFallFragment.newInstance(bean);
        } else if (position == 3) {
            //"交易所"
            return BourseFragment.newInstance(bean);
        } else {
            return BtckanDetailFragment.newInstance(bean);
        }

    }

    @Override
    public int getCount() {
        return coinMenuList.size();
    }
}
